#include "../include/stu.h"

void enter_sf(){ //学生 文件输入
    system("clear");
    FILE *fp;
    char filepath[20] = "./data/stu.txt";
    struct student *p1,*p2;
    p1 = head1;
    fp = fopen(filepath,"r+");
    if(fp == NULL){
        printf("can not find file!\n");
        exit(0);
    }
    while(!feof(fp)){
        p2 = (struct student *)malloc(sizeof(struct student));
        fscanf(fp,"%s %s %d",p2->id,p2->name,&p2->num);
        for(int i=0; i<p2->num; i++){
            fscanf(fp,"%d",&p2->class[i]);
        }
        fscanf(fp,"%d",&p2->credit);
        if(p1 == NULL){
            head1 = p2;
            p1 = p2;
        }else{
            p1->next = p2;
            p1 = p2;
        }
    }
    p2->next=NULL;
    p1 = head1;
    while(p1->next->next != NULL){
        p1 = p1->next;
    }
    p1->next = NULL;
    fclose(fp);
}
